$(document).ready(function () {
    siteTime();
    $(".to-cate").click(function () {
        $(".site-title").toggleClass("turnTo-180deg");
        $(".category-page").toggleClass("turnTo-0deg");
    });
    $(".extra-box .icon-sakura-flower").click(function () {
        $(".acticle-title").toggleClass("turnTo-180deg");
        $(".acticle-nav").toggleClass("turnTo-0deg");
    });
    $(".change-qq-url").click(function () {
        $("input[id='new-qq']").toggleClass("btn-hidden");
        $("input[id='new-url']").toggleClass("btn-hidden");
        if ($("input[id='new-url'] ~ span").text() == "-网站(https://)-") {
            $("input[id='new-url'] ~ span").text("-QQ-");
        } else if ($("input[id='new-url'] ~ span").text() == "-QQ-") {
            $("input[id='new-url'] ~ span").text("-网站(https://)-");
        } else ;
    });
    $(".reply-com").click(function () {
        $(".reply-flag").toggleClass("flag-show");
        var cur_id = $(this).siblings(".get-pk").text();
        var temp = $(".content-title").text();
        if (temp == "-评论-") {
            $(".content-title").text("-回复-");
            $(".reply-flag .reply-id").text(cur_id);
        } else if (temp == "-回复-") {
            $(".reply-flag .reply-id").text("-1");
            $(".content-title").text("-评论-");
        }
    });
    $(".reply-flag").click(function () {
        $(".reply-flag").toggleClass("flag-show");
        var temp = $(".content-title").text();
        if (temp == "-评论-") {
            $(".content-title").text("-回复-");
        } else if (temp == "-回复-") {
            $(".reply-flag .reply-id").text("-1");
            $(".content-title").text("-评论-");
        }
    });
    $(function () {
        var x = 10;
        var y = 20;
        $("a").mouseover(function (e) {
            this.myTitle = this.title;
            if (this.myTitle || this.myTitle == "javascript:;") {
                var tooltip = "<div id='tooltip'>" + this.myTitle + "</div>"; //创建DIV元素
            } else {
                var tooltip = "<div id='tooltip'>" + "UNKNOWN" + "</div>"; //创建DIV元素
            }
            this.title = "";

            var newLink = "<div id=\"link\"></div>";
            $("#link").append(tooltip); //追加到文档中
            $("#tooltip").css({
                "top": (e.pageY + y) + "px",
                "left": (e.pageX + x) + "px"
            }).show(); //设置X  Y坐标， 并且显示
        }).mouseout(function () {
            this.title = this.myTitle;
            $("#tooltip").remove(); //移除
        }).mousemove(function (e) {
            $("#tooltip").css({
                "top": (e.pageY + y) + "px",
                "left": (e.pageX + x) + "px"
            });
        })
    });
    $(function () {
        $("code.hljs").parent().addClass("code-box");
        var new_div = '<div class="code-type"></div>';
        $("code.hljs").parent().append(new_div);
        var tmp = $(".code-box>code").attr("class");
        if (tmp) {
            var class_list = tmp.split(" ");
            var code_type = "";
            for (var i = 0; i < class_list.length; ++i) {
                if (class_list[i] != "hljs") {
                    code_type = class_list[i];
                    break;
                } else {
                }
            }
            $(".code-box .code-type").text(code_type);
        } else {
            $(".code-box .code-type").text("UNKNOWN");
        }
    });
});


function getCommentInfo() {
    var curInfo = new Object();
    curInfo.platform = navigator.platform;// 浏览器正在运行的操作系统平台，包括Win16(windows3.x) 
    curInfo.browser = bro();
    if (!curInfo.cpuClass) {
        curInfo.cpuClass = "plastic";
    }
    return curInfo;
}

function bro() {
    let broName = 'Runing'
    let strStart = 0
    let strStop = 0
    let temp = ''
    let userAgent = window.navigator.userAgent // 包含以下属性中所有或一部分的字符串：appCodeName,appName,appVersion,language,platform
    // FireFox
    if (userAgent.indexOf('Firefox') !== -1) {
        strStart = userAgent.indexOf('Firefox')
        temp = userAgent.substring(strStart)
        broName = temp.replace('/', ' -v')
    }
    // Edge
    if (userAgent.indexOf('Edge') !== -1) {
        /* broName = 'Edge浏览器'; */
        strStart = userAgent.indexOf('Edge')
        temp = userAgent.substring(strStart)
        broName = temp.replace('/', ' -v')
    }
    // IE浏览器
    if (userAgent.match(/msie ([\d.]+)/)) {
        /* broName = 'IE浏览器'; */
        let s = userAgent.match(/msie ([\d.]+)/)
        let res = 'IE ' + s[1]
        broName = res + res.replace(/[^0-9.]/ig, '')
    }
    // 360极速模式可以区分360安全浏览器和360极速浏览器
    if (userAgent.indexOf('WOW') !== -1 && userAgent.indexOf('NET') < 0 && userAgent.indexOf('Firefox') < 0) {
        if (navigator.javaEnabled()) {
            broName = '360安全浏览器-极速模式'
        } else {
            broName = '360极速浏览器-极速模式'
        }
    }
    // 360兼容
    if (userAgent.indexOf('WOW') !== -1 && userAgent.indexOf('NET') !== -1 && userAgent.indexOf('MSIE') !== -1 && userAgent.indexOf('rv') < 0) {
        broName = '360兼容模式'
    }
    // Chrome浏览器
    if (userAgent.match(/Chrome\/([\d.]+)/)) {
        /* broName = 'Chrome浏览器'; */
        strStart = userAgent.indexOf('Chrome')
        strStop = userAgent.indexOf('Safari')
        temp = userAgent.substring(strStart, strStop)
        broName = temp.replace('/', ' -v')
    }
    // safari
    if (userAgent.match(/Version\/([\d.]+).*Safari/)) {
        strStop = userAgent.indexOf('Safari')
        temp = userAgent.substring(strStop)
        broName = temp.replace('/', ' -v')
    }
    // opera
    if (userAgent.match(/Opera.([\d.]+)/)) {
        strStop = userAgent.indexOf('Opera')
        temp = userAgent.substring(strStop)
        broName = temp.replace('/', ' -v')
    }
    return broName
}

function readAllFiles() {
    let ans = []
    //初始化fso对象;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    //根据路径获取文件夹;
    fldr = fso.GetFolder("./");
    //获取目录下的所有文件;
    fc = new Enumerator(fldr.files);
    //遍历所有文件
    for (; !fc.atEnd(); fc.moveNext()) {
        //取文件对象
        s = fc.item();
        //输出文件的类型和名称;
        //document.write("type:"+s.type + " name:"+s.name +"<br/>");
        ans.push(s.name);
    }
    return ans;
}

function siteTime() {
    window.setTimeout("siteTime()", 1000);
    var seconds = 1000;
    var minutes = seconds * 60;
    var hours = minutes * 60;
    var days = hours * 24;
    var years = days * 365;
    var today = new Date();
    var todayYear = today.getFullYear();
    var todayMonth = today.getMonth();
    var todayDate = today.getDate();
    var todayHour = today.getHours();
    var todayMinute = today.getMinutes();
    var todaySecond = today.getSeconds();
    /* Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳) 
    year - 作为date对象的年份，为4位年份值
    month - 0-11之间的整数，做为date对象的月份
    day - 1-31之间的整数，做为date对象的天数
    hours - 0(午夜24点)-23之间的整数，做为date对象的小时数
    minutes - 0-59之间的整数，做为date对象的分钟数
    seconds - 0-59之间的整数，做为date对象的秒数
    microseconds - 0-999之间的整数，做为date对象的毫秒数 */
    var t1 = Date.UTC(2019, 7, 15, 00, 00, 00);
    var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
    var diff = t2 - t1;
    var diffYears = Math.floor(diff / years);
    var diffDays = Math.floor((diff / days) - diffYears * 365);
    var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
    var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) / minutes);
    var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours - diffMinutes * minutes) / seconds);
    /* document.getElementById("sitetime").innerHTML=" 已运行"+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒" */
    document.getElementById("site-time").innerHTML = "Catch fish:" + (diffYears * 365 + diffDays) + "days-" + diffHours + "h-" + diffMinutes + "m-" + diffSeconds + "s";
};
